﻿using Microsoft.SharePoint;

namespace Eneta.Portal.Common
{
    public class SiteProvisioning
    {
        public static void EnsureContentTypes(SPWeb parentWeb, string webUrl, string contentTypeName, string pagesListName)
        {
            var currentWeb = parentWeb.Webs[webUrl];
            if (currentWeb == null)
                return;
            var contentTypes = currentWeb.Lists[pagesListName].ContentTypes;
            foreach (SPContentType type in parentWeb.Site.RootWeb.AvailableContentTypes)
            {
                if (type.Name == contentTypeName && contentTypes[type.Name] == null)
                {
                    contentTypes.Add(type);
                    break;
                }
            }
        }
    }
}
